package com.jwd.avmanager.util;

import com.jwd.avmanager.pojo.FileMessage;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileExistenceExample {
    public static boolean DoesTheFileExist(String filePath) {
        File file = new File(filePath);
         if (file.exists()) {
            DebugLogger.info("File exists.");
            return true;
        } else {
            DebugLogger.info("File does not exist.");
             return false;
        }
    }

     public static FileMessage FileInformation(String filePath) {
         File file = new File(filePath);
         if (file.exists()) {
             FileMessage fileMessage = new FileMessage();
             DebugLogger.info("File Name: " + file.getName());
             fileMessage.setFileName(file.getName());
             DebugLogger.info("Absolute Path: " + file.getAbsolutePath());
             fileMessage.setFilePath(file.getAbsolutePath());
             DebugLogger.info("File Size: " + file.length() + " bytes");
             fileMessage.setFileSize(file.length());
             Date currentTime = new Date(file.lastModified());
             SimpleDateFormat formatter =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             String dateString = formatter.format(currentTime);
             fileMessage.setFileData(dateString);
             DebugLogger.info("Last Modified: " + dateString);

             return fileMessage;
         } else {
             DebugLogger.info("File does not exist.");
             return null;
         }
     }
}